package com.example.yuntiku.dao.impl;

import com.example.yuntiku.dao.BaseDao;
import com.example.yuntiku.dao.ExamtypeDao;
import com.example.yuntiku.entity.Curriculum;
import com.example.yuntiku.entity.Examtype;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ExamtypeDaoImpl extends BaseDao implements ExamtypeDao {
    @Override
    public List<Examtype> selectAll() {
        List<Examtype> list = new ArrayList<>();
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            conn = super.getConnection();
            stmt = conn.prepareStatement("SELECT id,nametype FROM examtype");
            rs = stmt.executeQuery();
            while (rs.next()){
                Examtype examtype = new Examtype();
                examtype.setId(rs.getInt("id"));
                examtype.setNametype(rs.getString("nametype"));
                list.add(examtype);
            }
        }catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            super.closeAll(conn,stmt,rs);
        }
        return list;
    }
}
